package com.donfu.web.controller.wxhouse;

import com.donfu.common.annotation.Log;
import com.donfu.common.core.controller.BaseController;
import com.donfu.common.core.domain.AjaxResult;
import com.donfu.common.core.page.TableDataInfo;
import com.donfu.common.enums.BusinessType;
import com.donfu.common.utils.poi.ExcelUtil;
import com.donfu.system.domain.house.HouseAddress;
import com.donfu.system.service.house.IHouseAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 收货地址Controller
 * 
 * @author 曹雨心
 * @date 2021-12-01
 */
@Api(tags = "前台-收货地址管理")
@RestController
@RequestMapping("/wx/house/address")
public class WebHouseAddressController extends BaseController
{
    @Autowired
    private IHouseAddressService houseAddressService;


    /**
     * 查询收货地址列表 关联用户id
     */
    @ApiOperation("根据用户id查询该id所有地址")
   // @PreAuthorize("@ss.hasPermi('house:address:userList')")
    @GetMapping("/userList")
    public TableDataInfo userList(HouseAddress houseAddress)
    {
        startPage();
        List<HouseAddress> list = houseAddressService.selectHouseAddressListByUser(houseAddress);
        return getDataTable(list);
    }


    /**
     * 获取收货地址详细信息
     */
    @ApiOperation("查询单个地址的信息")
    //@PreAuthorize("@ss.hasPermi('house:address:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(houseAddressService.selectHouseAddressById(id));
    }

    /**
     * 新增收货地址
     */
    @ApiOperation("新增收货地址")
   // @PreAuthorize("@ss.hasPermi('house:address:add')")
    @Log(title = "收货地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseAddress houseAddress)
    {
        return toAjax(houseAddressService.insertHouseAddress(houseAddress));
    }

    /**
     * 修改收货地址
     */
    @ApiOperation("修改收货地址")
   // @PreAuthorize("@ss.hasPermi('house:address:edit')")
    @Log(title = "收货地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseAddress houseAddress)
    {
        return toAjax(houseAddressService.updateHouseAddress(houseAddress));
    }

    /**
     * 删除收货地址
     */
    @ApiOperation("删除收货地址")
  //  @PreAuthorize("@ss.hasPermi('house:address:remove')")
    @Log(title = "收货地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(houseAddressService.deleteHouseAddressByIds(ids));
    }
}
